package cn.bcsp.hotevent.controller;


import cn.bcsp.hotevent.pojo.Comments;
import cn.bcsp.hotevent.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-08-23
 */
@Controller
@RequestMapping("/comments")
@Api(tags = "消息控制")
public class CommentsController {

    @Resource
    private ICommentsService commentsService;

    @RequestMapping("/rem/{id}")
    public Map<String, Object> remove(@PathVariable("id") Integer id) {

        Map<String, Object> map = new HashMap<>();
        map.put("result", commentsService.removeById(id));
        return map;
    }


    @PostMapping("/doAdd")
    @ApiOperation("添加信息")
    @ResponseBody
    public Map<String, Object> doAdd(@RequestParam String content, @RequestParam Integer hid) {
        Map<String, Object> map = new HashMap<>();
        Comments comments = new Comments();
        comments.setContent(content);
        comments.setHotEventsId(hid);
        comments.setCommentDate(LocalDate.now());
        int res = commentsService.addInto(comments);
        map.put("result", res);
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        map.put("currentDate", dateFormat.format(date));
        return map;
    }

}
